package de.riceman.simpleGo.view.views.visualizationView;
public class Vector3D {
	private double x;
	private double y;
	private double z;
	
  	public Vector3D(double x, double y, double z) {
		
		this.x = x;
		this.y = y;
		this.z = z;
		
  	}

	public Vector3D(int x, int y, int z) {
	
		this.x = x;
		this.y = y;
		this.z = z;
		
	}

	public Vector3D() {
	
		x = 0.0;
		y = 0.0;
		z = 0.0;
	}
	
	public double getX() {
	
		return x;
		
	}
	
	public double getY() {
		
		return y;
		
	}
	
	public double getZ() {
		return z;
	}
	
	public void setX(double x) {
		
		this.x = x;
	
	}
	
	public void setY(double y) {
		
		this.y = y;
	
	}

	public void setZ(double z) {
		this.z = z;
	}
	
	public void setXY(double x, double y) {
		this.x = x;
		this.y = y;
	}
	
	public void setXYZ(double x, double y, double z) {
	
		this.x = x;
		this.y = y;
		this.z = z;
		
	}

	public void setVector(Vector3D v) {
	
		x = v.getX();
		y = v.getY();
		z = v.getZ();	
	}
	
	public Vector3D copy() {
	
		return new Vector3D(x, y, z);
	}
	
	public double magnitude() {
	
		return (double)Math.sqrt( x * x + y * y + z * z);
		
	}

	public Vector3D add(Vector3D v) {
	
		return new Vector3D(x + v.getX(), y + v.getY(), z + v.getZ());
		
	}

	public Vector3D subtract(Vector3D v) {
		
		return new Vector3D(x - v.getX(), y - v.getY(), z - v.getZ());
		
	}

	public Vector3D multiply(double n) {
	
		return new Vector3D(x * n, y * n, z * n);
		
	}
	
	public Vector3D divide(double n) {
	
		return new Vector3D(x / n, y / n, z / n);
	}

	public void normalize() {
	
		double m = magnitude();
		
		x = x / m;
		y = y / m;
		z = z / m;
		
	}
	
	public void limit(double max) {
	
		if (magnitude() > max) {
			normalize();
			x *= max;
			y *= max;
			z *= max;
		}
		
	}
	
	public double heading2D() {
	
		double angle = (double)Math.atan2(y * -1.0, x);
		return -1.0 * angle;
		
	}
	
	public static Vector3D add(Vector3D v1, Vector3D v2) {
	
		return new Vector3D(v1.getX() + v2.getX(), v1.getY() + v2.getY(), v1.getZ() + v2.getZ());
		
	}

	public static Vector3D subtract(Vector3D v1, Vector3D v2) {
	
		return new Vector3D(v1.getX() - v2.getX(), v1.getY() - v2.getY(), v1.getZ() - v2.getZ());
	}
	
	public static Vector3D divide(Vector3D v1, double n) {
	
		return new Vector3D(v1.getX() / n, v1.getY() / n, v1.getZ() / n);
		
	}

	public static Vector3D multiply(Vector3D v1, double n) {
		
		return new Vector3D(v1.getX() * n , v1.getY() * n, v1.getZ() * n);
		
	}

	public static double distance(Vector3D v1, Vector3D v2) {
	
		double dx = v1.getX() - v2.getX();
		double dy = v1.getY() - v2.getY();
		double dz = v1.getZ() - v2.getZ();
		return (double)Math.sqrt(dx * dx + dy * dy + dz * dz);
		
	}
	
	public String toString() {
		return "(" + Double.toString(this.getX()) + "/" + Double.toString(this.getY()) + ")";
	}
	
}

